package com.example.myapp1211.Fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.fragment.app.Fragment;

import com.example.myapp1211.R;
import com.example.myapp1211.bean.ChatUser;

import java.util.ArrayList;
import java.util.List;

public class ChatFragment extends Fragment {
    ListView listView;
    List<ChatUser> chatUserList=new ArrayList<>();
    public ChatFragment(){
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_chat, container, false);
        initView(view);
        getUser();
        ChatUserAdapter chatUserAdapter=new ChatUserAdapter(getContext(),R.layout.
                chatuser_item,chatUserList);
        listView.setAdapter(chatUserAdapter);
        return view;
    }
    private void getUser() {
        ChatUser chatUser = new ChatUser("张三","你好",R.drawable.person);
        chatUserList.add(chatUser);
        ChatUser chatUser1 = new ChatUser("李四","你好",R.drawable.person);
        chatUserList.add(chatUser1);
        ChatUser chatUser2 = new ChatUser("王五","你好",R.drawable.person);
        chatUserList.add(chatUser2);
    }

    private void initView(View view) {
        listView=view.findViewById(R.id.chatlist);
    }
}